//
// Created by liushuai on 12/22/19.
//
#include "yangangle.h"

std::vector<std::vector<int>> generate(int rows) {
    std::vector<std::vector<int>> result;
    if (rows > 0)
        result.push_back(std::vector<int>(1, 1));
    for (int i = 1; i < rows; i++) {
        {
            std::vector<int> temp = std::vector<int>(i + 1, 0);
            for (int j = 0; j <= i; j++) {
                if (j == 0)
                    temp.at(j) = 1;
                else if (j == i) {
                    temp.at(j) = 1;
                } else {
                    temp.at(j) = result.at(i - 1).at(j - 1) + result.at(i - 1).at(j);
                }
            }
            result.push_back(temp);
        }
    }
    return result;
};

std::vector<int> getRow(int rowIndex) {
    std::vector<int> result = std::vector<int>(rowIndex+1,0);
    int i = 1;
    result.at(0) = 1;
    for(i;i<rowIndex+1;i++){
        int temp = 0;
        for(int j=1;j<=i;j++){
            temp = result.at(j);
            result.at(j) = temp+result.at(j-1);
            if(i==j)
                result.at(i) = 1;
        }
    }
    return result;
};
